C::::::::::::::::::::::: MAG_DEC :::::::::::::::::::::::::::
C.... This subroutine caculates the Earth's magnetic declination 
C.... for any date of any year. It is based on linear interpolation between
C.... 1980 and 2012. It is most accurate close to the years 1980 and 2012
C.... Programmed by Xiaobei and P. Richards April 2013
      SUBROUTINE MAG_DEC(YYYYDDD,  !.. Date YYYYDDD
     >                      GLAT,  !.. Latitude (degrees, -90 to 90)
     >                     GLONG,  !.. Longitude (degrees, 0 to 360)
     >                      DECL)  !.. OUTPUT: Longitude (degrees, 0 to 360)
     
      IMPLICIT NONE                !.. Stops automatic typing
      INTEGER NLONG,NLAT           !.. Longitude and latitude array dimensions
      PARAMETER (NLONG=37,NLAT=37) !.. size of longitude and latitude array
      INTEGER YYYYDDD              !.. Date YYYYDDD
      INTEGER DAY, YEAR            !.. Used to calculate fractional year        !..
      REAL GLAT,GLONG,DECL         !.. Latitude, Longitude, Declination output
      REAL DEC12,DEC80             !.. declinations at (lat,long) for 2012 and 1980.
      REAL ALONG(NLONG)            !.. Longitude Array
      REAL ALAT(NLAT)              !.. Latitude Array
      REAL DEC1980(NLONG,NLAT)     !.. Declination Array
      REAL DEC2012(NLONG,NLAT)     !.. Declination Array
      REAL DATE                    !.. Fractional year       
      REAL K,B                     !.. Slope and ordinate for linear interpolation

      DAY=MOD(YYYYDDD,1000)            !.. extract day of year
      YEAR=INT(YYYYDDD/1000)           !.. extract year
      DATE=REAL(YEAR)+REAL(DAY)/367.0  !.. convert a fractional year

       !..get declination of the same latitude and longitude in 2012     
       CALL GETDEC(GLAT,GLONG,NLONG,NLAT,ALONG,ALAT,DEC2012,DEC12)

       !..get declination of the same latitude and longitude in 1980      
       CALL GETDEC(GLAT,GLONG,NLONG,NLAT,ALONG,ALAT,DEC1980,DEC80)
        
       !.. Get the components of the linear fit equation Y=K*X+B
       K=(DEC12-DEC80)/(2012-1980)   !.. slope
       B=DEC80-K*1980                !.. ordinate
       DECL=K*DATE + B            !.. Declination
c       IF(GLAT.LT.-60) DECL=16   !.. Sth hemisphere
c       IF(GLAT.GT.55) DECL=-9.43   !.. Nth hemisphere
                     
       RETURN  !===== End of executable statements

      !... Fill up the longitude, latitude, and magnetic declination arrays
      DATA ALONG/0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,
     >  160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,
     >  310,320,330,340,350,360/
      DATA ALAT/-90,-85,-80,-75,-70,-65,-60,-55,-50,-45,-40,-35,-30,
     >  -25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,
     >  70,75,80,85,90/

      !..-- The declinations are loaded in latitude slices. The first NLONG
      !..-- values are for the first latitude in the ALAT array
      DATA DEC1980/-27.5,-37.5,-47.5,-57.5,-67.5,-77.5,-87.5,-97.5,
     > -107.5,-117.5,-127.5,-137.5,-147.5,-157.5,-167.5,-177.5,172.5,
     > 162.5,152.5,142.5,132.5,122.5,112.5,102.5,92.5,82.5,72.5,62.5,
     > 52.5,42.5,32.5,22.5,12.5,2.5,-7.5,-17.5,-27.5,
     > -23.3,-32.2,-41.1,-50.2,-59.5,-69.0,-78.8,-88.7,-99.0,-109.5,
     > -120.4,-131.5,-143.0,-154.7,-166.7,-178.8,169.1,157.1,145.3,
     > 133.9,122.8,112.1,101.7,91.7,82.1,72.7,63.5,54.5,45.7,36.9,28.3,
     > 19.7,11.1,2.6,-6.0,-14.6,-23.3,
     > -20.9,-28.8,-36.9,-45.3,-53.9,-62.8,-71.9,-81.5,-91.4,-101.9,
     > -113.0,-124.9,-137.7,-151.6,-166.5,177.9,162.2,147.0,132.9,
     > 120.0,108.4,98.0,88.4,79.4,71.0,62.8,54.9,47.1,39.5,31.9,24.3,
     > 16.8,9.3,1.9,-5.6,-13.2,-20.9,
     > -19.7,-26.8,-34.1,-41.9,-49.9,-58.2,-66.8,-75.6,-84.8,-94.5,
     > -105.0,-116.7,-130.3,-146.8,-167.0,169.8,146.8,127.0,111.4,99.2,
     > 89.4,81.1,73.8,67.1,60.5,54.1,47.6,41.0,34.2,27.4,20.6,13.8,7.1,
     > 0.5,-6.1,-12.8,-19.7,
     > -19.2,-25.5,-32.3,-39.5,-47.0,-54.8,-62.7,-70.7,-78.8,-87.0,
     > -95.8,-105.6,-117.8,-135.9,-168.8,142.9,110.1,92.9,82.4,75.0,
     > 69.3,64.5,60.2,55.9,51.6,46.9,41.7,36.1,30.0,23.7,17.2,10.8,4.6,
     > -1.5,-7.3,-13.2,-19.2,
     > -19.4,-24.9,-31.1,-37.8,-44.9,-52.1,-59.3,-66.3,-72.9,-79.0,
     > -84.7,-89.8,-94.0,-95.8,37.1,65.3,63.5,60.7,57.8,55.1,52.8,50.7,
     > 48.8,46.7,44.3,41.1,37.2,32.4,26.8,20.6,14.2,7.8,1.7,-3.9,-9.2,
     > -14.2,-19.4,
     > -20.0,-24.7,-30.1,-36.3,-43.0,-49.8,-56.2,-62.0,-66.8,-70.3,
     > -71.7,-69.4,-58.5,-26.9,14.8,34.0,40.6,42.6,42.7,42.0,41.2,40.4,
     > 39.9,39.2,38.2,36.5,33.6,29.6,24.3,18.1,11.3,4.7,-1.5,-6.9,
     > -11.6,-15.8,-20.0,
     > -21.2,-24.8,-29.3,-35.0,-41.2,-47.5,-53.1,-57.6,-60.4,-61.0,
     > -58.0,-48.9,-31.0,-6.9,12.8,24.3,30.1,32.8,33.7,33.7,33.4,33.1,
     > 33.1,33.2,33.2,32.4,30.6,27.2,22.2,15.8,8.6,1.4,-5.1,-10.4,
     > -14.6,-18.0,-21.2,
     > -22.6,-25.0,-28.5,-33.5,-39.3,-45.0,-49.8,-52.9,-53.8,-51.6,
     > -44.9,-32.8,-16.6,-0.6,11.5,19.5,24.3,27.0,28.1,28.3,28.0,27.8,
     > 27.9,28.3,28.8,28.8,27.7,25.0,20.3,13.7,5.9,-1.9,-8.8,-14.1,
     > -17.9,-20.5,-22.6,
     > -24.3,-25.3,-27.5,-31.6,-37.0,-42.2,-46.1,-47.9,-47.0,-42.5,
     > -33.8,-21.7,-9.0,1.9,10.3,16.3,20.4,22.9,24.1,24.4,24.2,23.9,
     > 24.0,24.3,24.9,25.3,24.8,22.7,18.3,11.6,3.3,-5.2,-12.4,-17.6,
     > -21.0,-23.1,-24.3,
     > -25.7,-25.4,-26.1,-29.0,-33.8,-38.6,-41.7,-42.4,-40.0,-34.0,
     > -24.9,-14.3,-4.6,3.1,9.2,14.0,17.6,20.0,21.1,21.4,21.2,20.9,
     > 20.9,21.0,21.5,22.0,21.9,20.3,16.2,9.4,0.6,-8.2,-15.5,-20.6,
     > -23.7,-25.2,-25.7,
     > -26.3,-24.9,-23.8,-25.3,-29.5,-33.9,-36.5,-36.3,-33.0,-26.5,
     > -17.8,-9.1,-2.0,3.6,8.2,12.2,15.3,17.5,18.6,18.9,18.8,18.5,
     > 18.3,18.3,18.5,19.0,19.1,17.8,13.9,7.1,-1.8,-10.8,-18.0,-22.7,
     > -25.4,-26.6,-26.3,
     > -25.9,-23.4,-20.6,-20.5,-23.8,-28.0,-30.4,-29.9,-26.4,-20.1,
     > -12.5,-5.5,-0.3,3.8,7.4,10.7,13.5,15.5,16.5,16.8,16.6,16.4,
     > 16.2,16.0,16.0,16.4,16.5,15.3,11.6,4.9,-4.0,-12.9,-19.7,-24.0,
     > -26.2,-26.8,-25.9,
     > -24.2,-20.8,-16.9,-15.2,-17.5,-21.4,-23.9,-23.6,-20.4,-14.8,
     > -8.4,-3.0,0.8,3.8,6.6,9.5,12.0,13.9,14.8,15.0,14.8,14.6,14.4,
     > 14.1,14.0,14.2,13.2,11.2,9.5,2.9,-5.9,-14.4,-20.8,-24.5,-26.1,
     > -25.9,-24.2,
     > -21.5,-17.6,-13.1,-10.4,-11.6,-15.2,-17.9,-18.0,-15.4,-10.7,
     > -5.4,-1.2,1.5,3.7,6.0,8.6,10.9,12.6,13.5,13.5,13.2,13.0,12.8,
     > 12.5,12.2,12.4,12.5,11.3,7.7,1.1,-7.3,-15.4,-21.3,-24.5,-25.3,
     > -24.1,-21.5,
     > -18.3,-14.3,-9.8,-6.8,-7.1,-10.0,-12.8,-13.3,-11.4,-7.5,-3.3,
     > -0.1,1.9,3.5,5.5,7.8,10.0,11.6,12.4,12.3,11.8,11.6,11.4,11.1,
     > 10.8,11.0,11.1,9.8,6.1,-0.4,-8.5,-16.1,-21.5,-24.0,-23.9,-21.7,
     > -18.3,
     > -15.1,-11.2,-7.2,-4.3,-4.0,-6.3,-8.9,-9.7,-8.3,-5.3,-1.8,0.6,
     > 2.0,3.2,4.9,7.1,9.3,10.9,11.7,11.4,10.8,10.5,10.3,10.0,9.8,10.0,
     > 10.0,8.6,4.8,-1.6,-9.5,-16.6,-21.3,-23.1,-22.1,-18.9,-15.1,
     > -12.1,-8.6,-5.3,-2.6,-2.0,-3.7,-6.1,-7.1,-6.2,-3.7,-0.9,0.9,
     > 1.8,2.7,4.3,6.5,8.7,10.4,11.1,10.8,10.0,9.6,9.5,9.2,9.1,9.3,9.2,
     > 7.7,3.7,-2.7,-10.3,-16.9,-21.0,-22.0,-20.1,-16.2,-12.1,
     > -9.7,-6.5,-3.8,-1.4,-0.7,-2.0,-4.1,-5.2,-4.6,-2.7,-0.5,0.92,
     > 1.5,2.1,3.6,5.8,8.1,10.0,10.9,10.4,9.6,9.2,9.0,8.8,8.7,8.8,8.6,
     > 6.8,2.7,-3.7,-11.0,-17.1,-20.5,-20.7,-18.1,-13.8,-9.7,
     > -7.8,-4.9,-2.6,-0.6,0.1,-0.9,-2.7,-3.9,-3.5,-2.0,-0.3,0.7,
     > 0.9,1.4,2.8,5.0,7.5,9.7,10.7,10.4,9.5,9.1,9.0,8.8,8.6,8.6,8.1,
     > 6.1,1.8,-4.6,-11.6,-17.2,-19.8,-19.4,-16.2,-11.8,-7.8,
     > -6.3,-3.7,-1.7,0.0,0.7,-0.1,-1.7,-2.8,-2.7,-1.6,-0.3,0.3,0.2,
     > 0.4,1.7,3.9,6.7,9.3,10.6,10.5,9.7,9.4,9.4,9.2,8.9,8.7,7.9,5.5,
     > 0.8,-5.6,-12.3,-17.2,-19.2,-18.1,-14.6,-10.2,-6.3,
     > -5.3,-2.8,-1.0,0.5,1.1,0.5,-0.9,-2.0,-2.0,-1.2,-0.4,-0.3,-0.7,
     > -0.7,0.4,2.7,5.7,8.7,10.4,10.7,10.3,10.1,10.1,10.0,9.6,9.1,7.8,
     > 4.9,-0.1,-6.7,-13.1,-17.4,-18.6,-16.9,-13.4,-9.0,-5.3,
     > -4.6,-2.1,-0.4,1.0,1.6,1.1,-0.1,-1.1,-1.4,-1.0,-0.6,-0.9,-1.7,
     > -2.0,-1.1,1.2,4.5,7.9,10.2,11.0,11.0,11.1,11.3,11.1,10.6,9.6,
     > 7.8,4.3,-1.2,-7.9,-14.0,-17.6,-18.1,-16.0,-12.4,-8.2,-4.6,
     > -4.2,-1.7,0.1,1.4,2.0,1.7,0.7,-0.2,-0.6,-0.6,-0.8,-1.6,-2.8,
     > -3.4,-2.7,-0.4,3.1,6.8,9.7,11.3,11.9,12.4,12.7,12.5,11.8,10.5,
     > 8.0,3.8,-2.3,-9.3,-15.1,-18.0,-17.9,-15.5,-11.8,-7.7,-4.2,
     > -4.0,-1.3,0.6,1.9,2.6,2.4,1.7,0.9,0.3,-0.2,-0.9,-2.4,-4.0,
     > -5.0,-4.5,-2.2,1.5,5.6,9.1,11.5,12.9,13.9,14.4,14.2,13.2,11.5,
     > 8.4,3.4,-3.5,-10.8,-16.4,-18.7,-18.0,-15.2,-11.5,-7.5,-4.0,
     > -4.0,-1.1,1.0,2.4,3.2,3.3,2.9,2.2,1.4,0.5,-1.0,-3.1,-5.3,-6.6,
     > -6.2,-3.9,-0.1,4.4,8.5,11.7,13.9,15.4,16.2,16.0,14.9,12.6,8.8,
     > 2.8,-4.9,-12.7,-18.0,-19.8,-18.6,-15.5,-11.6,-7.7,-4.0,
     > -4.3,-1.1,1.3,3.0,4.1,4.5,4.4,3.9,2.9,1.3,-1.0,-3.9,-6.7,
     > -8.3,-8.0,-5.6,-1.7,3.1,7.8,11.8,14.9,17.0,18.1,18.1,16.8,14.0,
     > 9.3,2.1,-6.7,-14.9,-20.0,-21.3,-19.6,-16.2,-12.2,-8.1,-4.3,
     > -4.7,-1.2,1.7,3.8,5.2,6.1,6.4,6.0,4.7,2.4,-0.8,-4.6,-8.0,-9.9,
     > -9.7,-7.3,-3.1,2.0,7.3,12.1,15.9,18.7,20.2,20.4,19.0,15.7,9.8,
     > 1.1,-9.1,-17.8,-22.6,-23.4,-21.3,-17.6,-13.3,-8.9,-4.7,
     > -5.5,-1.4,2.0,4.6,6.7,8.1,8.8,8.5,7.0,3.9,-0.4,-5.3,-9.4,
     > -11.6,-11.3,-8.7,-4.4,1.1,6.8,12.3,17.0,20.5,22.6,23.1,21.7,
     > 17.7,10.4,-0.4,-12.4,-21.7,-26.1,-26.3,-23.6,-19.5,-14.8,
     > -10.1,-5.5,
     > -6.5,-1.9,2.2,5.7,8.5,10.6,11.8,11.6,9.8,5.9,0.3,-5.8,-10.7,
     > -13.1,-12.8,-10.0,-5.4,0.3,6.6,12.7,18.1,22.5,25.4,26.4,25.1,
     > 20.5,11.2,-2.8,-17.4,-27.1,-30.7,-30.0,-26.7,-22.1,-16.9,-11.6,
     > -6.5,
     > -7.8,-2.4,2.6,6.9,10.6,13.4,15.2,15.4,13.3,8.6,1.6,-6.0,
     > -11.8,-14.5,-14.1,-11.1,-6.2,-0.1,6.6,13.3,19.5,24.7,28.6,
     > 30.5,29.7,24.5,12.2,-7.2,-25.1,-34.4,-36.7,-34.8,-30.6,-25.3,
     > -19.5,-13.6,-7.8,
     > -9.1,-2.9,2.9,8.2,12.9,16.6,19.1,19.8,17.7,12.3,3.8,-5.5,
     > -12.4,-15.5,-15.0,-11.8,-6.6,-0.2,6.9,14.1,21.0,27.2,32.3,35.5,
     > 35.8,30.4,13.3,-16.1,-37.2,-44.3,-44.2,-40.6,-35.2,-29.0,-22.4,
     > -15.7,-9.1,
     > -10.5,-3.4,3.4,9.6,15.2,19.9,23.3,24.8,23.3,17.7,7.8,-3.6,
     > -12.0,-15.7,-15.2,-11.8,-6.4,0.2,7.6,15.4,23.0,30.2,36.6,41.6,
     > 44.0,39.7,13.6,-36.7,-54.9,-56.4,-52.8,-47.0,-40.2,-32.9,-25.4,
     > -17.9,-10.5,
     > -11.9,-4.0,3.6,10.7,17.2,22.9,27.4,30.1,29.9,25.4,15.4,2.2,
     > -8.4,-13.4,-13.4,-10.1,-4.8,2.0,9.6,17.7,26.0,34.3,42.3,49.7,
     > 55.8,57.4,-5.0,-76.3,-75.2,-69.0,-61.5,-53.5,-45.2,-36.8,-28.4,
     > -20.0,-11.9,
     > -13.8,-5.2,3.0,10.8,18.2,24.9,30.6,34.9,37.0,35.6,29.1,17.5,
     > 4.9,-2.9,-5.1,-3.2,1.5,7.8,15.4,23.8,32.8,42.4,52.9,64.8,81.1,
     > 122.6,-135.4,-106.4,-91.8,-80.2,-69.7,-59.8,-50.2,-40.8,-31.6,
     > -22.6,-13.8,
     > -18.0,-8.9,-0.1,8.4,16.5,24.1,31.2,37.5,42.7,46.5,48.3,47.7,
     > 44.5,39.7,35.5,33.7,35.1,39.4,46.2,55.5,67.5,83.2,104.5,133.7,
     > 168.7,-160.0,-136.4,-118.3,-103.5,-90.5,-78.7,-67.6,-57.0,-46.8,
     > -37.0,-27.3,-18.0,
     > -35.0,-25.0,-15.0,-5.0,5.0,15.0,25.0,35.0,45.0,55.0,65.0,75.0,
     > 85.0,95.0,105.0,115.0,125.0,135.0,145.0,155.0,165.0,175.0,
     > -175.0,-165.0,-155.0,-145.0,-135.0,-125.0,-115.0,-105.0,-95.0,
     > -85.0,-75.0,-65.0,-55.0,-45.0,-35.0/
      DATA DEC2012 /-29.6,-39.6,-49.6,-59.6,-69.6,-79.6,-89.6,-99.6,
     > -109.6,-119.6,-129.6,-139.6,-149.6,-159.6,-169.6,-179.6,170.4,
     > 160.4,150.4,140.4,130.4,120.4,110.4,100.4,90.4,80.4,70.4,60.4,
     > 50.4,40.4,30.4,20.4,10.4,0.4,-9.6,-19.6,-29.6,
     > -25.1,-34.0,-43.2,-52.4,-61.9,-71.5,-81.4,-91.5,-101.8,-112.5,
     > -123.4,-134.6,-146.0,-157.8,-169.6,178.4,166.4,154.6,143.0,
     > 131.7,120.8,110.2,100.0,90.1,80.5,71.2,62.1,53.1,44.3,35.6,27.0,
     > 18.4,9.8,1.2,-7.5,-16.2,-25.1,
     > -22.3,-30.5,-38.9,-47.6,-56.5,-65.7,-75.1,-84.9,-95.0,-105.6,
     > -116.8,-128.9,-141.8,-155.7,-170.5,174.3,159.0,144.4,130.8,
     > 118.3,107.1,96.8,87.3,78.4,70.0,61.9,54.0,46.2,38.6,31.0,23.5,
     > 16.1,8.6,1.1,-6.5,-14.3,-22.3,
     > -20.6,-28.2,-36.2,-44.5,-53.0,-61.6,-70.5,-79.5,-88.9,-98.7,
     > -109.5,-121.5,-135.6,-152.5,-172.6,165.4,144.1,125.8,111.1,99.3,
     > 89.5,81.1,73.7,66.7,60.0,53.5,46.9,40.2,33.5,26.8,20.1,13.5,6.9,
     > 0.3,-6.4,-13.4,-20.6,
     > -19.7,-26.9,-34.5,-42.5,-50.7,-58.9,-67.0,-75.0,-83.1,-91.4,
     > -100.5,-110.9,-124.5,-144.9,-178.4,140.9,112.7,96.2,85.4,77.4,
     > 71.1,65.8,61.0,56.3,51.6,46.6,41.2,35.4,29.3,23.0,16.8,10.6,4.7,
     > -1.1,-7.0,-13.1,-19.7,
     > -19.5,-26.2,-33.6,-41.1,-49.2,-56.8,-64.1,-70.8,-77.2,-83.2,
     > -89.1,-94.9,-101.3,-111.9,109.2,78.1,71.1,66.2,62.2,58.7,55.6,
     > 52.9,50.3,47.6,44.7,41.1,36.8,31.7,25.9,19.7,13.5,7.5,2.0,-3.1,
     > -8.1,-13.5,-19.5,
     > -19.7,-26.0,-33.2,-40.8,-48.2,-55.2,-61.4,-66.7,-71.0,-74.0,
     > -75.1,-72.8,-61.6,-24.9,22.7,40.6,45.9,47.1,46.6,45.5,44.2,43.0,
     > 41.8,40.6,39.0,36.7,33.3,28.8,23.1,16.8,10.3,4.1,-1.2,-5.7,-9.9,
     > -14.4,-19.7,
     > -20.3,-26.0,-32.9,-40.2,-47.3,-53.5,-58.5,-62.2,-64.1,-63.8,
     > -59.7,-49.6,-30.1,-4.5,16.0,27.6,33.5,36.0,36.8,36.7,36.2,35.6,
     > 35.1,34.7,34.1,32.9,30.4,26.3,20.7,14.0,6.9,0.4,-4.9,-9.0,-12.4,
     > -15.9,-20.3,
     > -21.2,-26.1,-32.4,-39.4,-45.9,-51.3,-55.1,-57.0,-56.6,-53.0,
     > -44.9,-31.6,-14.9,1.0,13.2,21.3,26.4,29.1,30.3,30.5,30.4,30.1,
     > 29.9,29.9,29.9,29.3,27.6,24.0,18.5,11.3,3.5,-3.6,-9.1,-12.8,
     > -15.4,-17.9,-21.2,
     > -22.2,-25.9,-31.4,-37.8,-43.7,-48.2,-50.8,-51.1,-48.4,-42.3,
     > -32.2,-19.7,-7.4,3.1,11.3,17.4,21.7,24.3,25.6,26.0,26.0,25.9,
     > 25.7,25.8,26.0,25.9,24.7,21.6,16.1,8.5,0.0,-7.6,-13.3,-16.8,
     > -18.8,-20.3,-22.2,
     > -23.2,-25.2,-29.4,-35.1,-40.4,-44.0,-45.4,-44.2,-39.9,-32.4,
     > -22.3,-12.0,-3.3,3.9,9.8,14.6,18.3,20.6,21.9,22.5,22.6,22.5,
     > 22.4,22.3,22.5,22.5,21.7,19.0,13.5,5.6,-3.4,-11.4,-17.0,-20.3,
     > -21.9,-22.7,-23.2,
     > -23.7,-23.5,-26.0,-30.7,-35.4,-38.4,-38.9,-36.7,-31.6,-24.0,
     > -15.0,-7.0,-0.8,4.2,8.6,12.5,15.6,17.8,18.9,19.5,19.7,19.8,19.6,
     > 19.4,19.4,19.4,18.8,16.2,10.9,2.8,-6.5,-14.5,-19.9,-22.9,-24.3,
     > -24.5,-23.7,
     > -23.0,-20.7,-20.9,-24.4,-28.7,-31.5,-31.7,-29.2,-24.2,-17.3,
     > -9.7,-3.6,0.6,4.2,7.6,10.9,13.6,15.5,16.5,17.0,17.3,17.4,17.3,
     > 17.0,16.8,16.7,16.0,13.6,8.3,0.1,-9.1,-16.9,-21.9,-24.5,-25.5,
     > -25.1,-23.0,
     > -20.9,-16.7,-15.0,-17.1,-21.1,-24.1,-24.5,-22.4,-18.1,-12.2,
     > -6.0,-1.4,1.5,4.0,6.8,9.5,11.9,13.6,14.5,14.9,15.2,15.4,15.3,
     > 15.0,14.6,14.3,13.6,11.2,5.9,-2.3,-11.2,-18.6,-23.1,-25.1,-25.5,
     > -24.3,-20.9,
     > -17.7,-12.6,-9.5,-10.4,-13.9,-17.2,-18.1,-16.7,-13.4,-8.6,
     > -3.5,0.0,1.9,3.7,6.0,8.4,10.6,12.1,12.8,13.2,13.4,13.6,13.6,
     > 13.2,12.8,12.5,11.7,9.2,3.8,-4.2,-12.8,-19.6,-23.5,-24.9,-24.3,
     > -22.0,-17.7,
     > -14.1,-8.9,-5.4,-5.3,-8.2,-11.4,-12.9,-12.2,-9.8,-6.0,-1.9,
     > 0.8,2.0,3.3,5.3,7.5,9.6,11.0,11.6,11.8,11.9,12.1,12.1,11.8,11.4,
     > 11.0,10.1,7.5,2.0,-5.8,-13.9,-20.1,-23.4,-20.1,-22.2,-18.9,-14.1,
     > -10.7,-6.1,-2.7,-2.0,-4.1,-7.1,-8.9,-8.8,-7.2,-4.3,-0.9,1.1,
     > 1.8,2.8,4.6,6.8,8.7,10.1,10.6,10.6,10.7,10.9,11.0,10.7,10.3,9.9,
     > 8.9,6.1,0.6,-7.1,-14.6,-20.2,-22.7,-22.2,-19.5,-15.4,-10.7,
     > -7.9,-4.1,-1.0,0.0,-1.5,-4.1,-5.9,-6.3,-5.3,-3.1,-0.5,1.0,1.4,
     > 2.2,3.9,6.0,8.0,9.4,9.9,9.8,9.8,9.9,10.0,9.8,9.5,9.1,8.0,4.9,
     > -0.7,-8.0,-15.0,-20.0,-21.7,-20.3,-16.7,-12.3,-7.9,
     > -5.7,-2.5,0.1,1.3,0.2,-2.1,-3.9,-4.4,-3.9,-2.3,-0.3,0.7,0.8,
     > 1.5,3.2,5.3,7.3,8.9,9.5,9.3,9.2,9.3,9.5,9.3,9.0,8.6,7.2,3.9,-1.7,
     > -8.7,-15.2,-19.4,-20.4,-18.3,-14.2,-9.7,-5.7,
     > -4.1,-1.4,0.8,2.0,1.3,-0.7,-2.4,-3.0,-2.8,-1.8,-0.4,0.3,0.1,
     > 0.6,2.2,4.4,6.6,8.4,9.1,9.0,8.9,9.0,9.2,9.1,8.8,8.2,6.6,3.0,-2.7,
     > -9.4,-15.2,-18.8,-19.1,-16.4,-12.1,-7.6,-4.1,
     > -2.9,-0.6,1.3,2.5,2.1,0.3,-1.3,-2.0,-2.0,-1.4,-0.5,-0.3,-0.7,
     > -0.4,1.1,3.3,5.7,7.8,8.9,8.9,8.8,9.1,9.4,9.3,8.9,8.1,6.1,2.2,
     > -3.6,-9.9,-15.2,-18.0,-17.7,-14.7,-10.4,-6.1,-2.9,
     > -1.9,0.1,1.8,2.9,2.6,1.1,-0.4,-1.1,-1.3,-1.1,-0.7,-1.0,-1.6,
     > -1.6,-0.3,1.9,4.6,7.1,8.6,9.0,9.1,9.4,9.9,9.9,9.4,8.2,5.7,1.4,
     > -4.6,-10.5,-15.2,-17.3,-16.4,-13.3,-9.1,-5.0,-1.9,
     > -1.3,0.6,2.2,3.2,3.0,1.7,0.4,-0.3,-0.6,-0.8,-0.9,-1.6,-2.7,
     > -2.9,-1.8,0.4,3.3,6.1,8.1,9.0,9.5,10.0,10.6,10.7,10.1,8.5,5.5,
     > 0.7,-5.3,-11.2,-15.2,-16.6,-15.3,-12.1,-8.1,-4.2,-1.3,
     > -0.8,1.1,2.5,3.5,3.5,2.4,1.3,0.6,0.1,-0.4,-1.1,-2.4,-3.8,-4.4,
     > -3.4,-1.2,1.8,5.0,7.5,9.0,10.0,10.9,11.6,11.7,11.0,9.0,5.5,0.2,
     > -6.2,-11.9,-15.4,-16.1,-14.4,-11.2,-7.4,-3.6,-0.8,
     > -0.4,1.5,2.9,3.9,4.0,3.3,2.3,1.6,1.0,0.1,-1.2,-3.1,-5.0,-5.9,
     > -5.1,-2.9,0.3,3.8,6.8,9.0,10.5,11.8,12.7,12.9,12.0,9.7,5.6,-0.4,
     > -7.1,-12.6,-15.7,-15.9,-13.9,-10.7,-7.0,-3.3,-0.4,
     > -0.3,1.8,3.2,4.3,4.7,4.3,3.6,2.9,2.0,0.7,-1.3,-3.8,-6.2,-7.4,
     > -6.8,-4.6,-1.3,2.5,6.0,8.9,11.1,12.8,13.9,14.1,13.0,10.4,5.7,
     > -0.9,-8.0,-13.6,-16.3,-16.1,-13.9,-10.6,-6.9,-3.3,-0.3,
     > -0.4,1.9,3.6,4.9,5.7,5.7,5.3,4.5,3.3,1.4,-1.3,-4.6,-7.5,-9.0,
     > -8.5,-6.2,-2.7,1.3,5.3,8.7,11.6,13.8,15.1,15.3,14.1,11.1,5.8,
     > -1.5,-9.1,-14.8,-17.2,-16.7,-14.3,-10.9,-7.2,-3.5,-0.4,
     > -0.6,2.0,4.1,5.7,6.9,7.5,7.4,6.6,4.9,2.3,-1.3,-5.4,-8.8,-10.6,
     > -10.1,-7.7,-4.1,0.3,4.6,8.6,12.1,14.7,16.4,16.7,15.3,11.9,5.9,
     > -2.3,-10.5,-16.3,-18.5,-17.8,-15.2,-11.7,-7.8,-4.0,-0.6,
     > -1.1,2.0,4.6,6.8,8.5,9.7,10.0,9.2,7.0,3.5,-1.1,-6.1,-10.2,
     > -12.1,-11.6,-9.1,-5.2,-0.5,4.2,8.7,12.6,15.7,17.7,18.1,16.6,
     > 12.7,5.8,-3.5,-12.4,-18.4,-20.4,-19.5,-16.7,-13.0,-8.9,-4.8,-1.1,
     > -1.7,2.0,5.3,8.1,10.6,12.4,13.1,12.4,9.8,5.3,-0.7,-6.9,-11.6,
     > -13.6,-13.0,-10.2,-6.0,-1.1,3.9,8.8,13.2,16.7,19.1,19.7,18.1,
     > 13.6,5.4,-5.3,-15.2,-21.2,-23.1,-21.9,-18.9,-14.9,-10.4,-5.9,
     > -1.7,-2.5,2.,6.1,9.8,13.1,15.6,16.9,16.3,13.4,7.8,0.2,-7.4,-12.9,
     > -15.1,-14.3,-11.2,-6.7,-1.5,3.9,9.1,13.9,17.8,20.6,21.5,19.9,
     > 14.5,4.6,-8.2,-19.2,-25.2,-26.7,-25.1,-21.7,-17.3,-12.4,-7.4,
     > 2.5,-3.4,2.,7.1,11.8,15.9,19.3,21.3,21.2,18.2,11.6,2.1,-7.5,
     > -14.0,-16.4,-15.4,-12.0,-7.2,-1.7,4.0,9.6,14.7,19.1,22.3,23.6,
     > 21.8,15.2,2.6,-13.2,-25.2,-30.8,-31.4,-29.1,-25.1,-20.1,-14.6,
     > -9.0,-3.4,-4.1,2.1,8.2,13.9,19.0,23.3,26.3,27.2,24.7,17.5,6.0,
     > -6.2,-14.2,-17,-16,-12.5,-7.5,-1.8,4.2,10.2,15.7,20.5,24.1,25.6,
     > 23.5,14.9,-2.4,-22.1,-34.1,-38.1,-37.3,-33.8,-28.9,-23.2,-17.0,
     > -10.6,-4.1,
     > -4.7,2.4,9.3,16.0,22.1,27.5,31.8,34.1,33.2,27.1,14.6,-0.8,
     > -11.8,-16.1,-15.6,-12.3,-7.3,-1.5,4.7,10.9,16.8,21.9,25.9,27.3,
     > 23.9,10.5,-15.5,-37.4,-46.0,-46.8,-43.8,-38.8,-32.7,-26.1,-19.1,
     > -11.9,-4.7,
     > -5.1,2.7,10.4,17.9,25.0,31.6,37.3,41.7,43.8,41.9,33.4,17.2,
     > 0.5,-8.8,-11.1,-9.3,-5.1,0.2,6.2,12.3,18.3,23.4,26.9,26.6,16.6,
     > -15.4,-48.6,-59.4,-59.8,-56.0,-50.3,-43.6,-36.3,-28.7,-20.9,
     > -13.0,-5.1,
     > -5.8,2.7,11.1,19.4,27.5,35.4,42.8,49.7,55.8,60.7,63.7,63.6,
     > 58.5,47.4,33.3,22.8,18.3,18.2,20.8,24.7,28.6,30.4,17.6,-77.7,
     > -96.7,-94.5,-88.6,-81.5,-73.7,-65.6,-57.3,-48.4,-40.3,-31.7,
     > -23.1,-14.4,-5.8,
     > -10.4,-0.4,9.6,19.6,29.6,39.6,49.6,59.6,69.6,79.6,89.6,
     > 99.6,109.6,119.6,129.6,139.6,149.6,159.6,169.6,179.6,-170.4,
     > -160.4,-150.4,-140.4,-130.4,-120.4,-110.4,-100.4,-90.4,-80.4,
     > -70.4,-60.4,-50.4,-40.4,-30.4,-20.4,-10.4/
      END
C::::::::::::::::::::::: GETDEC :::::::::::::::::::::::::::
C...... This routine uses a table to calculate the magnetic declination
C...... (DECPT) for use with a neutral wind model. The table was constructed 
C...... using the map at http://www.ngdc.noaa.gov/geomagmodels/Declination.jsp
C...... See map at http://magnetic-declination.com/
C...... See also " The Earth's magnetic Field" by Robert Merrill and
C...... Michael McElhinny, Academic Press p 18. (UAH library # QC816.M47)
C...... Web reference with interactive map http://magnetic-declination.com/ 
C...... The declination at the specified location (degrees) is obtained
C...... by bilinear interpolation of the table values
C...... Written by Phil Richards, August 1995
C...... This code is not accurate near the magnetic poles
C...... GLAT, GLONG, and DECPT are in degrees
       SUBROUTINE GETDEC(GLAT,    !.. Geographic latitude
     >                  TLONG,    !.. Temporary Geographic longitude
     >                  NLONG,    !.. # of longitudes for data
     >                   NLAT,    !.. # of latitudes for data
     >                  ALONG,    !.. Longitude Array
     >                   ALAT,    !.. Latitude Array
     >                  DECLS,    !.. Declination Array
     >                  DECPT)    !.. OUTPUT: Magnetic declination
       IMPLICIT NONE
       !..--- NLONG=# longs, NLAT= # lats. I,J,K are array indices
       INTEGER J,K                !.. loop control variables
       INTEGER NLONG,NLAT           !.. See I/O parameters
       REAL GLAT,TLONG              !.. See I/O parameters
       REAL DECPT                   !.. See I/O parameters
       REAL GLONG                   !.. Geographic longitude
       REAL ALONG(NLONG)            !.. Longitude Array
       REAL ALAT(NLAT)              !.. Latitude Array
       REAL DECLS(NLONG,NLAT)       !.. Declination Array
       REAL RLAT,RLONG              !.. Latitude and longitude variables

       !.. Make sure longitude is between 0 and 360
       GLONG=TLONG
       IF(GLONG.LT.0.OR.GLONG.GE.360) GLONG=0
       !.. Find the index in the longitude array 
       CALL BISPLIT(1,NLONG,NLONG,GLONG,ALONG,J)
       
       !.. Find the index in the latitude array
       CALL BISPLIT(1, NLAT, NLAT, GLAT, ALAT, K)
       IF(K.GE.NLAT) K=NLAT-1   !.. Make sure K is within array boundary

      !..-- Now do the bilinear fit (Press et al. Numerical Recipes. page 96)
       RLAT=(GLAT-ALAT(K))/(ALAT(K+1)-ALAT(K))
       RLONG=(GLONG-ALONG(J))/(ALONG(J+1)-ALONG(J))
       DECPT=(1-RLAT)*(1-RLONG)*DECLS(J,K)+RLONG*(1-RLAT)*DECLS(J+1,K)
     >   +RLAT*RLONG*DECLS(J+1,K+1)+(1-RLONG)*RLAT*DECLS(J,K+1)

      RETURN
      END
C::::::::::::::::::::::::::: BISPLIT ::::::::::::::::::::::::::::::::::
C--- Use bisection to find the nearest altitude ZARRAY(K) to desired
C--- altitude (Z). Modified in Feb 93 to do both ascending and descending
C--- arrays. Written by Phil Richards, modified March 2004
      SUBROUTINE BISPLIT(BEGIN,  !.. first index in array
     >                   FINAL,  !.. ending index in array
     >                    IDIM,  !.. array dimension
     >                       Z,  !.. scalar to look for
     >                  ZARRAY,  !.. array to search
     >                   FIRST)  !.. index of Z in ZARRAY
      IMPLICIT NONE
      INTEGER BEGIN,IDIM,FINAL
      INTEGER FIRST,LAST,MID !.. variable indices of sub arrays
      REAL ZARRAY(IDIM),Z

      FIRST=BEGIN  !.. set pointer to first element
      LAST=FINAL   !.. set pointer to last element

      !.. This section for ZARRAY increasing
      IF(ZARRAY(BEGIN).LE.ZARRAY(FINAL)) THEN
 10      CONTINUE
             MID=(FIRST+LAST)/2
             IF(Z.LT.ZARRAY(MID)) THEN
                LAST=MID-1
             ELSE
                FIRST=MID+1
             ENDIF  
         IF(FIRST.LT.LAST) GO TO 10
         IF(Z.LT.ZARRAY(FIRST)) FIRST=FIRST-1
         IF(Z.LT.ZARRAY(BEGIN)) FIRST=BEGIN

      !.. This section for ZARRAY decreasing
      ELSE
 110      CONTINUE
             MID=(FIRST+LAST)/2
             IF(Z.GE.ZARRAY(MID)) THEN
                LAST=MID-1
             ELSE
                FIRST=MID+1
             ENDIF  
         IF(FIRST.LT.LAST) GO TO 110
         IF(Z.GT.ZARRAY(FIRST)) FIRST=FIRST-1
         IF(Z.LT.ZARRAY(FINAL)) FIRST=FINAL
      ENDIF
      !..BISPLIT=FIRST
      RETURN
      END
C::::::::::::::::::::::: DIP_ANG :::::::::::::::::::::::::::
C.... This subroutine is the main interface routine to calculate the Earth's
C.... magnetic dip angle. At each location it gets the dip angle for 1980 and 
C.... 2012 and then does a linear interpolation in time. It can handle any year
C.... but it is most accurate close to the years 1980 and 2012
C.... The data were obtained from http://www.ngdc.noaa.gov/geomag-web/#igrfgrid
C.... See  map at http://www.ngdc.noaa.gov/geomagmodels/dip angle.jsp
C.... See map at http://magnetic-dip angle.com/
C.... The dip angle at the specified location (degrees) is obtained
C.... by bilinear interpolation of the table values in the data statements
C.... Programmed by Xiaobei and P. Richards April 2013 for declination and
C.... converted in February 2014 for dip angle by P. Richards
      SUBROUTINE DIP_ANG(YYYYDDD,  !.. Date YYYYDDD
     >                      GLAT,  !.. Latitude (degrees, -90 to 90)
     >                     GLONG,  !.. Longitude (degrees, 0 to 360)
     >                      DIPL)  !.. OUTPUT: Longitude (degrees, 0 to 360)
     
      IMPLICIT NONE                !.. Stops automatic typing
      INTEGER NLONG,NLAT           !.. Longitude and latitude array dimensions
      PARAMETER (NLONG=37,NLAT=37) !.. size of longitude and latitude array
      INTEGER YYYYDDD              !.. Date YYYYDDD
      INTEGER DAY, YEAR            !.. Used to calculate fractional year        !..
      REAL GLAT,GLONG,DIPL         !.. Latitude, Longitude, dip angle output
      REAL DIP12,DIP80             !.. dip angles at (lat,long) for 2012 and 1980.
      REAL ALONG(NLONG)            !.. Longitude Array
      REAL ALAT(NLAT)              !.. Latitude Array
      REAL DIP1980(NLONG,NLAT)     !.. dip angle Array
      REAL DIP2012(NLONG,NLAT)     !.. dip angle Array
      REAL DATE                    !.. Fractional year       
      REAL K,B                     !.. Slope and ordinate for linear interpolation

      DAY=MOD(YYYYDDD,1000)            !.. extract day of year
      YEAR=INT(YYYYDDD/1000)           !.. extract year
      DATE=REAL(YEAR)+REAL(DAY)/367.0  !.. convert a fractional year

       !..get dip angle of the same latitude and longitude in 2012     
       CALL GETDIP(GLAT,GLONG,NLONG,NLAT,ALONG,ALAT,DIP2012,DIP12)

       !..get dip angle of the same latitude and longitude in 1980      
       CALL GETDIP(GLAT,GLONG,NLONG,NLAT,ALONG,ALAT,DIP1980,DIP80)
        
       !.. Get the components of the linear fit equation Y=K*X+B
       K=(DIP12-DIP80)/(2012-1980)   !.. slope
       B=DIP80-K*1980                !.. ordinate
       DIPL=K*DATE + B            !.. dip angle
              
       RETURN  !===== End of executable statements

      !... Fill up the longitude, latitude, and magnetic dip angle arrays
      DATA ALONG/0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,
     >  160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,
     >  310,320,330,340,350,360/
      DATA ALAT/-90,-85,-80,-75,-70,-65,-60,-55,-50,-45,-40,-35,-30,
     >  -25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,
     >  70,75,80,85,90/

      !..-- The dip angles are loaded in latitude slices. The first NLONG
      !..-- values are for the first latitude in the ALAT array
      DATA DIP1980/   37*-74.4,     -71.3,-71.5,-71.8,-72.2,-72.6,
     > -73.1,-73.6,-74.2,-74.8,-75.3,-75.9,-76.4,-76.9,-77.3,-77.5,
     > -77.7,-77.7,-77.6,-77.4,-77.1,-76.7,-76.3,-75.7,-75.2,-74.6,
     > -74.0,-73.4,-72.9,-72.4,-72.0,-71.7,-71.4,-71.2,-71.1,-71.1,
     > -71.1,-71.3,-68.4,-68.7,-69.2,-69.9,-70.6,-71.5,-72.5,-73.6,
     > -74.8,-76.0,-77.1,-78.3,-79.3,-80.1,-80.7,-81.0,-81.0,-80.7,
     > -80.2,-79.4,-78.5,-77.5,-76.4,-75.3,-74.1,-73.0,-71.9,-70.9,
     > -70.0,-69.3,-68.7,-68.3,-68.0,-67.9,-67.9,-68.1,-68.4,-65.8,
     > -66.3,-66.9,-67.7,-68.7,-69.9,-71.2,-72.8,-74.5,-76.3,-78.2,
     > -80.0,-81.6,-83.0,-84.0,-84.3,-84.0,-83.2,-82.1,-80.7,-79.3,
     > -77.8,-76.2,-74.6,-73.0,-71.4,-69.8,-68.4,-67.2,-66.2,-65.5,
     > -65.1,-64.9,-64.9,-65.1,-65.4,-65.8,-63.6,-64.2,-64.9,-65.8,
     > -66.9,-68.3,-70.0,-71.9,-74.2,-76.5,-79.0,-81.4,-83.7,-85.8,
     > -87.3,-87.1,-85.8,-84.1,-82.3,-80.6,-78.8,-77.0,-75.2,-73.2,
     > -71.3,-69.3,-67.3,-65.5,-64.0,-62.9,-62.1,-61.8,-61.8,-62.1,
     > -62.5,-63.1,-63.6,-62.1,-62.8,-63.5,-64.3,-65.4,-66.9,-68.8,
     > -71.1,-73.7,-76.5,-79.4,-82.3,-85.2,-87.8,-89.3,-87.1,-84.9,
     > -82.8,-80.8,-79.0,-77.1,-75.3,-73.3,-71.3,-69.1,-66.8,-64.5,
     > -62.4,-60.6,-59.2,-58.5,-58.4,-58.9,-59.6,-60.5,-61.4,-62.1,
     > -61.3,-62.0,-62.6,-63.2,-64.1,-65.6,-67.7,-70.2,-73.1,-76.2,
     > -79.4,-82.4,-84.9,-86.4,-86.0,-84.3,-82.3,-80.2,-78.3,-76.4,
     > -74.6,-72.8,-70.9,-68.9,-66.6,-64.2,-61.6,-59.1,-57.0,-55.5,
     > -54.9,-55.1,-56.1,-57.5,-59.0,-60.3,-61.3,-61.2,-62.0,-62.3,
     > -62.6,-63.3,-64.6,-66.7,-69.3,-72.4,-75.6,-78.7,-81.3,-83.0,
     > -83.4,-82.5,-80.9,-79.1,-77.2,-75.3,-73.4,-71.6,-69.9,-68.0,
     > -66.1,-63.8,-61.3,-58.5,-55.7,-53.3,-51.7,-51.2,-51.9,-53.7,
     > -55.8,-58.0,-59.9,-61.2,-61.6,-62.5,-62.7,-62.5,-62.7,-63.8,
     > -65.7,-68.4,-71.5,-74.6,-77.4,-79.3,-80.2,-80.0,-79.0,-77.5,
     > -75.7,-73.9,-71.9,-70.1,-68.3,-66.5,-64.7,-62.8,-60.6,-58.1,
     > -55.3,-52.3,-49.6,-47.8,-47.5,-48.8,-51.3,-54.4,-57.3,-59.8,
     > -61.6,-62.1,-63.3,-63.4,-62.9,-62.6,-63.1,-64.8,-67.4,-70.3,
     > -73.1,-75.3,-76.6,-76.8,-76.3,-75.3,-73.8,-72.2,-70.3,-68.4,
     > -66.4,-64.5,-62.7,-60.9,-59.1,-57.0,-54.5,-51.7,-48.5,-45.6,
     > -43.7,-43.6,-45.5,-48.9,-52.8,-56.6,-59.8,-62.1,-62.3,-63.9,
     > -64.2,-63.4,-62.5,-62.5,-63.8,-66.0,-68.6,-71.0,-72.6,-73.3,
     > -73.1,-72.4,-71.3,-70.0,-68.3,-66.4,-64.4,-62.3,-60.4,-58.5,
     > -56.6,-54.8,-52.7,-50.4,-47.6,-44.3,-41.1,-39.1,-39.2,-41.8,
     > -46.1,-50.9,-55.5,-59.4,-62.3,-61.8,-63.9,-64.5,-63.6,-62.3,
     > -61.7,-62.4,-64.2,-66.4,-68.3,-69.3,-69.4,-68.9,-68.0,-67.0,
     > -65.7,-64.0,-62.1,-59.9,-57.8,-55.7,-53.7,-51.7,-49.8,-47.8,
     > -45.6,-42.7,-39.3,-36.0,-33.8,-34.2,-37.5,-42.6,-48.4,-53.8,
     > -58.3,-61.8,-60.3,-63.0,-63.8,-63.0,-61.3,-60.1,-60.4,-61.7,
     > -63.5,-64.8,-65.3,-65.0,-64.2,-63.2,-62.2,-60.9,-59.2,-57.1,
     > -54.8,-52.5,-50.3,-48.2,-46.1,-44.1,-42.1,-39.9,-37.0,-33.4,
     > -29.8,-27.5,-28.2,-32.2,-38.4,-45.1,-51.2,-56.4,-60.3,-57.8,
     > -60.6,-61.7,-60.9,-59.1,-57.5,-57.3,-58.2,-59.6,-60.5,-60.6,
     > -59.8,-58.8,-57.8,-56.8,-55.4,-53.6,-51.4,-48.9,-46.3,-44.0,
     > -41.8,-39.6,-37.5,-35.4,-33.2,-30.2,-26.4,-22.5,-20.2,-21.2,
     > -26.0,-33.2,-40.9,-47.9,-53.5,-57.8,-54.0,-56.8,-57.9,-57.1,
     > -55.1,-53.3,-52.8,-53.5,-54.5,-55.2,-54.9,-53.9,-52.7,-51.7,
     > -50.6,-49.2,-47.3,-44.8,-42.0,-39.2,-36.7,-34.4,-32.2,-30.0,
     > -27.9,-25.5,-22.3,-18.2,-14.1,-11.8,-13.3,-18.7,-26.9,-35.7,
     > -43.5,-49.6,-54.0,-48.8,-51.3,-52.3,-51.5,-49.4,-47.4,-46.7,
     > -47.3,-48.2,-48.7,-48.2,-47.0,-45.7,-44.7,-43.7,-42.2,-40.1,
     > -37.3,-34.1,-31.0,-28.4,-26.0,-23.7,-21.5,-19.4,-16.9,-13.5,
     > -9.2,-4.9,-2.8,-4.6,-10.7,-19.8,-29.5,-38.1,-44.5,-48.8,-42.0,
     > -44.2,-44.9,-44.0,-41.8,-39.7,-39.0,-39.5,-40.5,-41.0,-40.3,
     > -39.0,-37.7,-36.7,-35.8,-34.3,-32.0,-28.9,-25.3,-21.9,-19.1,
     > -16.7,-14.4,-12.2,-10.1,-7.5,-4.0,0.5,4.6,6.5,4.4,-2.1,-11.8,
     > -22.3,-31.4,-38.0,-42.0,-33.6,-35.3,-35.8,-34.7,-32.5,-30.3,
     > -29.6,-30.3,-31.4,-31.9,-31.2,-29.9,-28.6,-27.8,-27.0,-25.5,
     > -23.1,-19.7,-15.7,-11.9,-9.0,-6.7,-4.5,-2.3,-0.2,2.3,5.9,10.2,
     > 14.1,15.6,13.3,6.7,-3.2,-14.0,-23.5,-30.0,-33.6,-23.6,-24.9,
     > -25.1,-23.9,-21.7,-19.5,-18.9,-19.6,-20.9,-21.5,-20.9,-19.6,
     > -18.5,-17.9,-17.3,-16.0,-13.5,-9.9,-5.6,-1.6,1.4,3.6,5.7,7.7,
     > 9.7,12.2,15.6,19.7,23.1,24.2,21.8,15.3,5.7,-5.0,-14.3,-20.5,
     > -23.6,-12.4,-13.3,-13.2,-12.0,-9.8,-7.8,-7.2,-8.0,-9.3,-10.0,
     > -9.6,-8.5,-7.6,-7.3,-7.0,-5.9,-3.6,0.1,4.5,8.6,11.5,13.6,15.5,
     > 17.4,19.4,21.7,24.9,28.4,31.3,32.1,29.6,23.5,14.5,4.6,-4.1,
     > -9.8,-12.4,-0.6,-1.1,-0.8,0.4,2.4,4.3,4.9,4.1,2.7,2.0,2.2,3.1,
     > 3.6,3.6,3.6,4.3,6.4,9.9,14.2,18.1,21.0,22.9,24.7,26.5,28.3,
     > 30.5,33.4,36.4,38.8,39.2,36.7,31.1,23.1,14.2,6.6,1.6,-0.6,11.3,
     > 11.0,11.5,12.6,14.3,15.9,16.5,15.8,14.6,13.9,14.0,14.5,14.8,
     > 14.4,14.0,14.3,15.9,19.0,23.0,26.7,29.3,31.2,32.9,34.6,36.4,
     > 38.5,41.0,43.6,45.4,45.4,43.0,38.0,31.0,23.6,17.1,13.0,11.3,
     > 22.4,22.4,22.9,23.9,25.4,26.7,27.2,26.7,25.7,25.0,25.0,25.3,
     > 25.2,24.5,23.7,23.6,24.7,27.3,30.7,34.0,36.5,38.3,40.0,41.7,
     > 43.5,45.5,47.7,49.9,51.3,51.0,48.6,44.2,38.4,32.3,27.1,23.8,
     > 22.4,32.5,32.5,33.0,34.0,35.2,36.2,36.7,36.3,35.6,35.1,35.0,
     > 35.0,34.7,33.7,32.6,32.1,32.7,34.6,37.5,40.3,42.6,44.4,46.1,
     > 47.9,49.7,51.7,53.7,55.6,56.6,56.1,53.7,49.8,44.9,40.1,36.1,
     > 33.5,32.5,41.2,41.3,41.8,42.7,43.6,44.5,44.9,44.7,44.3,43.9,
     > 43.8,43.6,43.0,41.8,40.5,39.6,39.7,41.1,43.3,45.7,47.8,49.6,
     > 51.4,53.2,55.1,57.1,59.1,60.7,61.3,60.6,58.3,54.8,50.8,47.0,
     > 44.0,42.0,41.2,48.7,48.8,49.3,50.0,50.8,51.5,51.9,51.9,51.7,
     > 51.5,51.4,51.1,50.3,48.9,47.4,46.3,46.0,46.8,48.4,50.4,52.3,
     > 54.2,56.0,58.0,60.0,62.0,63.9,65.3,65.7,64.8,62.5,59.4,56.1,
     > 53.1,50.8,49.3,48.7,55.1,55.2,55.6,56.2,56.9,57.5,57.9,58.0,
     > 58.1,58.1,58.0,57.5,56.6,55.1,53.5,52.2,51.6,51.9,53.1,54.7,
     > 56.4,58.3,60.3,62.3,64.4,66.4,68.2,69.5,69.7,68.6,66.4,63.6,
     > 60.8,58.4,56.6,55.5,55.1,60.4,60.5,60.9,61.4,62.0,62.5,63.0,
     > 63.3,63.6,63.7,63.6,63.2,62.1,60.6,58.9,57.5,56.7,56.7,57.4,
     > 58.7,60.3,62.2,64.2,66.3,68.5,70.5,72.3,73.3,73.3,72.1,70.0,
     > 67.5,65.1,63.1,61.7,60.8,60.4,64.9,65.0,65.3,65.8,66.3,66.8,
     > 67.3,67.8,68.3,68.6,68.6,68.1,67.0,65.5,63.8,62.3,61.4,61.2,
     > 61.7,62.7,64.1,65.9,67.9,70.1,72.3,74.3,76.0,76.9,76.7,75.4,
     > 73.3,71.0,68.9,67.2,66.0,65.3,64.9,68.8,68.8,69.1,69.5,69.9,
     > 70.5,71.1,71.7,72.4,72.8,72.9,72.4,71.3,69.9,68.2,66.8,65.9,
     > 65.5,65.8,66.6,67.9,69.6,71.5,73.7,75.8,77.8,79.4,80.2,79.7,
     > 78.3,76.3,74.2,72.4,70.9,69.8,69.1,68.8,72.2,72.1,72.3,72.6,
     > 73.1,73.7,74.4,75.2,75.9,76.5,76.7,76.2,75.2,73.8,72.4,71.1,
     > 70.1,69.7,69.9,70.5,71.6,73.1,75.0,77.0,79.1,81.0,82.5,83.0,
     > 82.4,80.8,78.9,77.1,75.4,74.1,73.1,72.5,72.2,75.1,75.0,75.2,
     > 75.5,75.9,76.5,77.3,78.1,79.0,79.7,79.9,79.6,78.7,77.5,76.2,
     > 75.0,74.2,73.8,73.8,74.4,75.3,76.6,78.2,80.0,82.0,83.8,85.2,
     > 85.5,84.6,83.0,81.2,79.5,78.1,76.9,76.0,75.4,75.1,77.8,77.7,
     > 77.8,78.0,78.5,79.1,79.9,80.7,81.6,82.3,82.6,82.4,81.8,80.8,
     > 79.7,78.8,78.1,77.7,77.7,78.1,78.9,79.9,81.3,82.8,84.5,86.1,
     > 87.3,87.3,86.2,84.6,83.0,81.6,80.4,79.4,78.6,78.1,77.8,80.3,
     > 80.2,80.3,80.5,80.9,81.5,82.2,82.9,83.7,84.4,84.8,84.8,84.4,
     > 83.7,82.9,82.2,81.7,81.5,81.5,81.7,82.3,83.1,84.1,85.3,86.6,
     > 88.0,89.0,88.5,87.2,85.8,84.5,83.4,82.4,81.6,81.0,80.5,80.3,
     > 82.8,82.7,82.8,83.0,83.3,83.7,84.2,84.8,85.4,86.0,86.4,86.5,
     > 86.4,86.1,85.7,85.4,85.1,84.9,84.9,85.1,85.5,86.0,86.7,87.5,
     > 88.3,89.3,89.6,88.6,87.6,86.7,85.8,85.0,84.3,83.7,83.3,82.9,
     > 82.8,85.3,85.3,85.3,85.4,85.6,85.8,86.1,86.4,86.7,87.0,87.3,
     > 87.6,87.7,87.8,87.8,87.8,87.8,87.8,87.9,88.0,88.1,88.4,88.6,
     > 88.9,89.0,89.0,88.7,88.3,87.8,87.4,86.9,86.5,86.1,85.8,85.6,
     > 85.4,85.3,  37*90.0/
      DATA DIP2012/37*-73.3,-70.1,-70.4,-70.6,-71.0,-71.5,-72.0,
     > -72.5,-73.1,-73.7,-74.3,-74.9,-75.4,-75.8,-76.2,-76.5,-76.6,
     > -76.7,-76.6,-76.3,-76.0,-75.6,-75.2,-74.6,-74.1,-73.5,-72.9,
     > -72.4,-71.8,-71.4,-71.0,-70.6,-70.3,-70.1,-70.0,-70.0,-70.0,
     > -70.1,-67.2,-67.5,-68.0,-68.7,-69.5,-70.4,-71.4,-72.6,-73.8,
     > -75.1,-76.3,-77.4,-78.4,-79.2,-79.8,-80.0,-80.0,-79.7,-79.1,
     > -78.3,-77.4,-76.4,-75.3,-74.2,-73.0,-71.9,-70.9,-69.9,-69.1,
     > -68.4,-67.8,-67.4,-67.1,-66.9,-66.9,-67.0,-67.2,-64.5,-65.0,
     > -65.6,-66.4,-67.5,-68.8,-70.3,-72.0,-73.8,-75.7,-77.6,-79.4,
     > -81.0,-82.3,-83.2,-83.4,-83.0,-82.2,-81.0,-79.6,-78.2,-76.7,
     > -75.1,-73.5,-71.9,-70.4,-68.9,-67.6,-66.4,-65.5,-64.9,-64.4,
     > -64.2,-64.1,-64.1,-64.3,-64.5,-62.4,-62.9,-63.5,-64.4,-65.7,
     > -67.3,-69.2,-71.4,-73.7,-76.2,-78.7,-81.2,-83.5,-85.4,-86.6,
     > -86.3,-84.9,-83.2,-81.4,-79.6,-77.8,-76.0,-74.1,-72.2,-70.2,
     > -68.3,-66.5,-64.8,-63.4,-62.4,-61.8,-61.5,-61.5,-61.6,-61.9,
     > -62.1,-62.4,-61.0,-61.4,-61.9,-62.9,-64.2,-66.1,-68.3,-70.9,
     > -73.7,-76.6,-79.5,-82.5,-85.3,-88.1,-89.3,-86.8,-84.5,-82.3,
     > -80.2,-78.2,-76.3,-74.4,-72.4,-70.3,-68.2,-65.9,-63.7,-61.8,
     > -60.2,-59.1,-58.7,-58.7,-59.1,-59.7,-60.2,-60.6,-61.0,-60.4,
     > -60.6,-61.0,-61.8,-63.2,-65.1,-67.6,-70.5,-73.5,-76.7,-79.8,
     > -82.8,-85.4,-86.9,-86.2,-84.3,-82.1,-79.9,-77.9,-75.9,-74.0,
     > -72.1,-70.1,-68.1,-65.8,-63.3,-60.9,-58.6,-56.8,-55.8,-55.6,
     > -56.2,-57.2,-58.4,-59.4,-60.0,-60.4,-60.7,-60.7,-60.8,-61.3,
     > -62.5,-64.5,-67.1,-70.1,-73.2,-76.4,-79.4,-81.9,-83.4,-83.7,
     > -82.7,-81.0,-79.0,-77.0,-75.0,-73.1,-71.2,-69.4,-67.5,-65.4,
     > -63.1,-60.6,-57.9,-55.3,-53.4,-52.4,-52.6,-53.9,-55.7,-57.7,
     > -59.2,-60.2,-60.7,-61.7,-61.6,-61.2,-61.3,-62.2,-64.0,-66.6,
     > -69.6,-72.7,-75.7,-78.1,-79.8,-80.4,-80.1,-79.0,-77.5,-75.7,
     > -73.8,-71.8,-69.9,-68.1,-66.2,-64.4,-62.3,-60.1,-57.5,-54.7,
     > -51.9,-49.8,-48.9,-49.6,-51.7,-54.5,-57.3,-59.6,-61.1,-61.7,
     > -63.0,-62.9,-62.2,-61.6,-62.0,-63.6,-66.0,-68.9,-71.8,-74.3,
     > -76.1,-77.0,-77.0,-76.3,-75.2,-73.8,-72.1,-70.2,-68.3,-66.4,
     > -64.6,-62.7,-60.8,-58.8,-56.6,-54.1,-51.2,-48.3,-46.0,-45.2,
     > -46.4,-49.3,-53.1,-56.8,-59.9,-62.0,-63.0,-64.2,-64.3,-63.3,
     > -62.2,-61.9,-63.0,-65.1,-67.7,-70.2,-72.2,-73.3,-73.5,-73.0,
     > -72.2,-71.2,-69.8,-68.2,-66.3,-64.4,-62.5,-60.6,-58.6,-56.7,
     > -54.7,-52.5,-50.0,-47.1,-44.1,-41.7,-41.1,-42.8,-46.6,-51.3,
     > -55.9,-59.8,-62.6,-64.2,-64.7,-65.2,-64.1,-62.5,-61.5,-61.9,
     > -63.6,-65.8,-67.8,-69.3,-69.8,-69.5,-68.7,-67.8,-66.7,-65.4,
     > -63.8,-62.0,-60.0,-58.1,-56.1,-54.0,-51.9,-49.8,-47.6,-45.1,
     > -42.2,-39.1,-36.6,-36.1,-38.5,-43.2,-48.9,-54.3,-58.9,-62.5,
     > -64.7,-64.2,-65.0,-64.0,-62.0,-60.3,-60.0,-61.1,-62.9,-64.5,
     > -65.5,-65.5,-64.8,-63.8,-62.9,-61.8,-60.6,-58.9,-57.0,-55.0,
     > -52.9,-50.8,-48.7,-46.4,-44.1,-41.9,-39.4,-36.4,-33.1,-30.5,
     > -30.2,-33.3,-39.0,-45.7,-51.9,-57.2,-61.4,-64.2,-62.2,-63.3,
     > -62.3,-60.0,-57.8,-56.9,-57.5,-58.8,-60.0,-60.7,-60.4,-59.4,
     > -58.2,-57.3,-56.3,-55.0,-53.3,-51.3,-49.1,-46.9,-44.7,-42.4,
     > -40.0,-37.6,-35.2,-32.6,-29.4,-25.9,-23.2,-23.2,-27.0,-33.8,
     > -41.6,-48.7,-54.6,-59.2,-62.2,-58.7,-59.7,-58.7,-56.2,-53.6,
     > -52.2,-52.4,-53.3,-54.4,-54.9,-54.4,-53.1,-51.9,-51.0,-50.1,
     > -48.8,-46.9,-44.7,-42.3,-39.9,-37.6,-35.2,-32.7,-30.1,-27.6,
     > -24.8,-21.4,-17.6,-14.8,-15.2,-19.8,-27.6,-36.5,-44.5,-50.9,
     > -55.7,-58.7,-53.5,-54.3,-53.1,-50.4,-47.5,-45.8,-45.7,-46.4,
     > -47.4,-47.8,-47.2,-45.8,-44.6,-43.9,-43.0,-41.6,-39.6,-37.1,
     > -34.4,-31.9,-29.5,-27.0,-24.4,-21.7,-19.0,-16.0,-12.4,-8.4,-5.7,
     > -6.4,-11.7,-20.4,-30.3,-39.2,-46.1,-50.8,-53.5,-46.5,-46.9,
     > -45.5,-42.7,-39.6,-37.7,-37.4,-38.1,-39.0,-39.4,-38.8,-37.5,
     > -36.3,-35.7,-35.0,-33.6,-31.4,-28.6,-25.6,-22.9,-20.4,-17.9,
     > -15.2,-12.4,-9.6,-6.5,-2.7,1.3,3.8,2.7,-3.0,-12.3,-23.0,-32.7,
     > -39.7,-44.2,-46.5,-37.7,-37.7,-36.2,-33.2,-29.9,-27.9,-27.6,
     > -28.3,-29.2,-29.7,-29.2,-27.9,-27.0,-26.6,-26.0,-24.6,-22.4,
     > -19.3,-16.0,-13.0,-10.4,-8.0,-5.3,-2.5,0.2,3.4,7.2,11.0,13.1,
     > 11.7,5.9,-3.6,-14.7,-24.7,-31.8,-35.9,-37.7,-27.3,-27.0,-25.3,
     > -22.3,-18.9,-16.9,-16.6,-17.2,-18.2,-18.8,-18.4,-17.3,-16.7,
     > -16.6,-16.2,-15.0,-12.6,-9.4,-5.8,-2.7,-0.1,2.3,4.8,7.5,10.1,
     > 13.2,16.9,20.3,21.9,20.3,14.6,5.3,-5.6,-15.5,-22.4,-26.0,-27.3,
     > -15.5,-15.0,-13.3,-10.3,-7.1,-5.1,-4.7,-5.4,-6.3,-6.9,-6.7,
     > -5.9,-5.6,-5.9,-5.8,-4.8,-2.6,0.7,4.3,7.5,10.1,12.3,14.7,17.2,
     > 19.7,22.6,25.9,28.8,30.0,28.2,22.8,14.2,4.0,-5.2,-11.6,-14.8,
     > -15.5,-3.1,-2.4,-0.7,2.0,5.1,6.9,7.2,6.7,5.9,5.2,5.3,5.7,5.7,
     > 5.1,4.8,5.5,7.4,10.4,14.0,17.2,19.6,21.7,23.9,26.2,28.5,31.2,
     > 34.1,36.5,37.2,35.3,30.4,22.7,13.7,5.5,-0.1,-2.7,-3.1,9.2,10.1,
     > 11.7,14.1,16.7,18.4,18.7,18.2,17.6,17.0,16.9,17.1,16.8,15.9,
     > 15.2,15.5,16.9,19.6,22.8,25.8,28.1,30.0,32.0,34.2,36.5,38.9,
     > 41.4,43.3,43.6,41.7,37.2,30.6,23.0,16.1,11.5,9.3,9.2,20.8,21.8,
     > 23.2,25.2,27.4,28.8,29.1,28.8,28.3,27.9,27.8,27.7,27.1,26.0,24.9,
     > 24.7,25.7,27.8,30.6,33.3,35.4,37.3,39.2,41.2,43.4,45.7,47.9,
     > 49.3,49.3,47.4,43.4,37.8,31.6,26.2,22.4,20.8,20.8,31.3,32.2,
     > 33.4,35.1,36.9,38.1,38.3,38.1,37.8,37.5,37.4,37.2,36.4,35.0,
     > 33.7,33.1,33.6,35.1,37.4,39.7,41.7,43.5,45.3,47.3,49.5,51.7,
     > 53.6,54.7,54.5,52.5,49.0,44.3,39.4,35.2,32.3,31.1,31.3,40.4,41.2,
     > 42.3,43.7,45.1,46.0,46.3,46.2,46.1,45.9,45.8,45.4,44.5,43.0,41.5,
     > 40.6,40.6,41.6,43.4,45.3,47.1,48.8,50.6,52.7,54.8,56.9,58.6,59.5,
     > 59.1,57.2,54.1,50.2,46.4,43.2,41.0,40.1,40.4,48.1,48.9,49.8,50.9,
     > 52.0,52.7,53.1,53.2,53.2,53.2,53.1,52.6,51.6,50.0,48.4,47.2,46.9,
     > 47.4,48.6,50.2,51.8,53.5,55.4,57.4,59.5,61.6,63.2,63.9,63.4,61.6,
     > 58.8,55.6,52.5,50.1,48.5,47.9,48.1,54.7,55.3,56.1,56.9,57.8,58.5,
     > 58.9,59.1,59.3,59.4,59.3,58.8,57.7,56.1,54.4,53.1,52.5,52.6,53.4,
     > 54.6,56.1,57.8,59.7,61.7,63.8,65.8,67.3,67.9,67.4,65.6,63.1,60.4,
     > 58.0,56.1,54.9,54.5,54.7,60.2,60.7,61.3,62.0,62.7,63.4,63.9,64.3,
     > 64.6,64.8,64.8,64.2,63.1,61.5,59.8,58.4,57.6,57.4,57.9,58.9,60.2,
     > 61.8,63.7,65.7,67.8,69.7,71.1,71.7,71.0,69.4,67.1,64.8,62.8,61.3,
     > 60.4,60.0,60.2,64.9,65.2,65.7,66.3,66.9,67.6,68.2,68.8,69.3,69.6,
     > 69.6,69.0,67.9,66.3,64.6,63.2,62.3,62.0,62.2,63.0,64.2,65.8,67.6,
     > 69.6,71.6,73.4,74.7,75.1,74.4,72.9,70.9,68.9,67.2,65.9,65.1,64.8,
     > 64.9,68.9,69.1,69.5,70.0,70.6,71.2,71.9,72.7,73.3,73.7,73.8,73.2,
     > 72.1,70.6,69.0,67.7,66.8,66.3,66.5,67.1,68.2,69.6,71.3,73.2,75.1,
     > 76.8,77.9,78.2,77.5,76.1,74.3,72.5,71.0,69.9,69.2,68.9,68.9,72.3,
     > 72.5,72.8,73.2,73.8,74.4,75.2,76.1,76.8,77.4,77.5,77.0,75.9,74.5,
     > 73.1,71.9,71.0,70.6,70.6,71.2,72.1,73.4,75.0,76.7,78.4,79.9,80.9,
     > 81.1,80.3,79.0,77.3,75.8,74.4,73.4,72.7,72.4,72.3,75.4,75.4,75.7,
     > 76.1,76.6,77.3,78.1,79.0,79.9,80.5,80.7,80.2,79.3,78.1,76.9,75.8,
     > 75.1,74.7,74.7,75.1,75.9,77.0,78.4,79.9,81.4,82.7,83.5,83.5,82.7,
     > 81.5,80.0,78.6,77.4,76.5,75.9,75.5,75.4,78.1,78.1,78.3,78.7,79.2,
     > 79.9,80.7,81.6,82.4,83.1,83.4,83.1,82.3,81.4,80.4,79.5,78.9,78.6,
     > 78.6,78.9,79.6,80.5,81.6,82.8,84.1,85.1,85.7,85.5,84.7,83.5,82.3,
     > 81.1,80.1,79.2,78.6,78.3,78.1,80.6,80.6,80.8,81.1,81.6,82.2,82.9,
     > 83.7,84.5,85.2,85.5,85.4,85.0,84.3,83.6,82.9,82.5,82.2,82.2,82.5,
     > 83.0,83.6,84.5,85.4,86.3,87.1,87.4,87.0,86.2,85.2,84.1,83.2,82.3,
     > 81.7,81.2,80.8,80.6,83.1,83.1,83.3,83.5,83.9,84.3,84.9,85.5,86.1,
     > 86.7,87.1,87.3,87.1,86.8,86.4,86.0,85.7,85.6,85.6,85.8,86.1,86.5,
     > 87.1,87.7,88.3,88.7,88.6,88.0,87.2,86.5,85.7,85.0,84.4,83.9,83.5,
     > 83.3,83.1,85.7,85.7,85.7,85.9,86.1,86.3,86.6,87.0,87.4,87.7,88.1,
     > 88.3,88.5,88.6,88.7,88.6,88.6,88.6,88.6,88.7,88.9,89.2,89.5,89.8,
     > 89.7,89.3,88.9,88.4,87.9,87.5,87.1,86.7,86.4,86.1,85.9,85.7,85.7,
     >   37*90.000/
      END
C::::::::::::::::::::::: GETDIP :::::::::::::::::::::::::::
C.... This subroutine calls BISPLIT to do the fitting by binary interpolation 
C.... in space. It locates the place in the latitude and longitude arrays and 
C.... then does a bilinear fit to get the dip angle
C.... Programmed by Xiaobei and P. Richards April 2013
       SUBROUTINE GETDIP(GLAT,    !.. Geographic latitude (deg.)
     >                  TLONG,    !.. Temporary Geographic longitude (deg.)
     >                  NLONG,    !.. # of longitudes for data
     >                   NLAT,    !.. # of latitudes for data
     >                  ALONG,    !.. Longitude Array
     >                   ALAT,    !.. Latitude Array
     >                  DIPLS,    !.. dip angle Array
     >                  DIPPT)    !.. OUTPUT: Magnetic dip angle (deg.)
       IMPLICIT NONE
       !..--- NLONG=# longs, NLAT= # lats. I,J,K are array indices
       INTEGER I,J,K,M              !.. loop control variables
       INTEGER NLONG,NLAT           !.. See I/O parameters
       REAL GLAT,TLONG              !.. See I/O parameters
       REAL DIPPT                   !.. See I/O parameters
       REAL GLONG                   !.. Geographic longitude
       REAL ALONG(NLONG)            !.. Longitude Array
       REAL ALAT(NLAT)              !.. Latitude Array
       REAL DIPLS(NLONG,NLAT)       !.. dip angle Array
       REAL RLAT,RLONG              !.. Latitude and longitude variables

       !.. Make sure longitude is between 0 and 360
       GLONG=TLONG
       IF(GLONG.LT.0.OR.GLONG.GE.360) GLONG=0
       !.. Find the index in the longitude array 
       CALL BISPLIT(1,NLONG,NLONG,GLONG,ALONG,J)
       
       !.. Find the index in the latitude array
       CALL BISPLIT(1, NLAT, NLAT, GLAT, ALAT, K)
       IF(K.GE.NLAT) K=NLAT-1   !.. Make sure K is within array boundary

      !..-- Now do the bilinear fit (Press et al. Numerical Recipes. page 96)
       RLAT=(GLAT-ALAT(K))/(ALAT(K+1)-ALAT(K))
       RLONG=(GLONG-ALONG(J))/(ALONG(J+1)-ALONG(J))
       DIPPT=(1-RLAT)*(1-RLONG)*DIPLS(J,K)+RLONG*(1-RLAT)*DIPLS(J+1,K)
     >   +RLAT*RLONG*DIPLS(J+1,K+1)+(1-RLONG)*RLAT*DIPLS(J,K+1)

      RETURN
      END
C::::::::::::::::::::::::::::::: CORRECT_DIP :::::::::::::::::::::::::::::::::::
C.....This routine corrects the magnetic dip angle from dipole to IGRF
C..... Written by P. Richards in February 2014
      SUBROUTINE CORRECT_DIP(JMAX,   !..  # of points on the field line
     >                         JQ,   !.. equatorial point
     >                       JDAY,   !.. YYYYddd
     >                      GLATN,   !.. North geographic latitude 
     >                      GLONN,   !.. North geographic longitude 
     >                      GLATF,   !.. South geographic latitude 
     >                      GLONF,   !.. South geographic longitude 
     >                          Z,   !.. Altitude array
     >                     COSINC,   !.. COS(DIP) dipole
     >                     COSDIP)   !.. OUTPUT: COS(DIP) IGRF
      IMPLICIT NONE
      INTEGER JMAX,JQ,JDAY
      INTEGER J,J300                !.. Loop variables
      REAL DIPMAG,DIPCORN,DIPCORS   !.. magnetic field factors
      REAL GLATN,GLONN,GLATF,GLONF
      DOUBLE PRECISION Z(401),COSINC(401),COSDIP(401)
      !.. Get the magnetic dip angle correction factors at 300 km
      J300=10     !.. in case the field line does not reach 300 km
      DO J=1,JQ
        IF(Z(J).LE.300)  J300=J  !.. Index for altitude 300 km
      ENDDO
      CALL DIP_ANG(JDAY,GLATN,GLONN,DIPMAG)  !.. get IGRF dip
      DIPMAG=DIPMAG/57.3
      DIPCORN=ABS(COS(DIPMAG)/COSINC(J300))
      CALL DIP_ANG(JDAY,GLATF,GLONF,DIPMAG)  !.. get IGRF dip
      DIPMAG=DIPMAG/57.3
      DIPCORS=ABS(COS(DIPMAG)/COSINC(JMAX-J300+1))

      DO J=1,JMAX
        IF(J.LE.JQ) COSDIP(J)=COSINC(J)*DIPCORN
        IF(J.GT.JQ) COSDIP(J)=COSINC(J)*DIPCORS
c        IF(J.GT.JQ) COSDIP(J)= -0.34   !.. Sth hemisphere
c        IF(J.LT.JQ) COSDIP(J)= 0.31    !.. Nth hemisphere
      ENDDO
      RETURN
      END